package com.masterclient.app.modules.income.adapter;

import android.content.Context;
import android.widget.ImageView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.baselibrary.utils.ViewTransformUtil;
import com.masterclient.app.R;
import com.masterclient.app.modules.income.dealer.model.DealerBankCardBean;

public class ManageBankCardAdapter extends BaseQuickAdapter<DealerBankCardBean, BaseViewHolder> {

    private Context mContext;
    private OnSetDefaultSelectedListener onSetDefaultSelectedListener;

    public ManageBankCardAdapter(Context mContext) {
        super(R.layout.item_bank_card_manage);
        this.mContext = mContext;
    }

    @Override
    protected void convert(BaseViewHolder helper, DealerBankCardBean item) {
        ImageView ivBank = helper.getView(R.id.iv_bank);
        ImageView ivCheck = helper.getView(R.id.iv_check);

        ViewTransformUtil.glideImageView(mContext, item.cardBg, ivBank, R.mipmap.user_head_default_icon);
        helper.setText(R.id.tv_bank_name, item.bankShort);
        helper.setText(R.id.tv_bank_code, item.card);
        if ("1".equals(item.isDefault)){
            ivCheck.setImageResource(R.mipmap.icon_bank_card_checked);
        }else {
            ivCheck.setImageResource(R.mipmap.icon_bank_card_check);
        }
        helper.getView(R.id.view_check).setOnClickListener(v -> {
            ivCheck.setImageResource(R.mipmap.icon_bank_card_checked);
            onSetDefaultSelectedListener.setDefaultSelected(helper.getLayoutPosition());
        });
        helper.addOnClickListener(R.id.view_unbind);
    }

    public void SetOnDefaultSelectedListener(OnSetDefaultSelectedListener onSetDefaultSelectedListener){
        this.onSetDefaultSelectedListener = onSetDefaultSelectedListener;
    }

    public interface OnSetDefaultSelectedListener{
        void setDefaultSelected(int position);
    }
}
